import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_logs/flutter_logs.dart';
import 'package:flutter_tv/tv_page.dart';

void main(){
  FlutterLogs();
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []);
    SystemChrome.setPreferredOrientations(
        [DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight]);
    return MaterialApp(
      title: '爱情TV',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  late Timer timer;

  @override
  void initState() {
    startTimeout();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      primary: true,
      backgroundColor: Colors.black54,
      body: Center(
        child: Text(
          '爱情TV',
          style: TextStyle(
            fontSize: 50,
            color: Colors.deepOrange,
            fontWeight: FontWeight.normal,
          ),
        ),
      ),
    );
  }

  _toPage() {
    Navigator.pushAndRemoveUntil(
      context,
      MaterialPageRoute(builder: (context) => TVPage()),
      (route) => false,
    );
  }

  static const timeout = const Duration(seconds: 3);

  startTimeout() {
    timer = Timer(timeout, handleTimeout);
    return timer;
  }

  void handleTimeout() {
    _toPage();
  }

  @override
  void dispose() {
    timer.cancel();
    super.dispose();
  }
}
